home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / mathtu1a / tutorfrm.frm < prev   
Text File  |  1999-10-07  |  9KB  |  301 lines

  1. VERSION 5.00
  2. Begin VB.Form TutorFrm 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Math Tutor"
  5.    ClientHeight    =   855
  6.    ClientLeft      =   45
  7.    ClientTop       =   615
  8.    ClientWidth     =   2175
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    ScaleHeight     =   855
  12.    ScaleWidth      =   2175
  13.    StartUpPosition =   2  'CenterScreen
  14.    Begin VB.TextBox Answer 
  15.       Height          =   285
  16.       Left            =   120
  17.       MultiLine       =   -1  'True
  18.       TabIndex        =   3
  19.       ToolTipText     =   "Answer"
  20.       Top             =   480
  21.       Width           =   1935
  22.    End
  23.    Begin VB.TextBox Problem 
  24.       Enabled         =   0   'False
  25.       Height          =   285
  26.       Left            =   120
  27.       Locked          =   -1  'True
  28.       TabIndex        =   2
  29.       ToolTipText     =   "Math Problem"
  30.       Top             =   120
  31.       Width           =   1935
  32.    End
  33.    Begin VB.ListBox TimeLst 
  34.       Height          =   255
  35.       Left            =   120
  36.       TabIndex        =   1
  37.       Top             =   0
  38.       Visible         =   0   'False
  39.       Width           =   135
  40.    End
  41.    Begin VB.Timer Time 
  42.       Interval        =   1000
  43.       Left            =   240
  44.       Top             =   0
  45.    End
  46.    Begin VB.ListBox OptionT 
  47.       Height          =   255
  48.       Left            =   0
  49.       TabIndex        =   0
  50.       Top             =   0
  51.       Visible         =   0   'False
  52.       Width           =   135
  53.    End
  54.    Begin VB.Menu PauseCmd 
  55.       Caption         =   "&Pause"
  56.    End
  57.    Begin VB.Menu StopCmd 
  58.       Caption         =   "&Stop"
  59.    End
  60.    Begin VB.Menu ExitCmd 
  61.       Caption         =   "&Exit"
  62.    End
  63. End
  64. Attribute VB_Name = "TutorFrm"
  65. Attribute VB_GlobalNameSpace = False
  66. Attribute VB_Creatable = False
  67. Attribute VB_PredeclaredId = True
  68. Attribute VB_Exposed = False
  69. 'Name:  Math Tutor
  70. 'Author:  InfraRed
  71. 'Contact Info:  ICQ #:   17948286
  72. '               E-Mail:  InfraRed@flashmail.com
  73. '----------------Code Starts Here------------------
  74.  
  75. Dim AnswerN As Long
  76. Dim NumWrong As Integer
  77. Dim NumRight As Integer
  78. Dim CurTime As Integer
  79.  
  80. Private Sub Answer_KeyPress(KeyAscii As Integer)
  81. If KeyAscii = vbKeyReturn Then 'Here we are finding returns, deleting them, and activating the answer checker
  82. KeyAscii = 0
  83. CheckA
  84. Exit Sub
  85. End If
  86. Const Numbers$ = "0123456789"
  87. If KeyAscii <> 8 Then 'This part will only let numbers go though, so people cannot type in letters/other characters and cause an error
  88.   If InStr(Numbers, Chr(KeyAscii)) = 0 Then
  89.   KeyAscii = 0
  90.   Exit Sub
  91.   End If
  92. End If
  93. End Sub
  94.  
  95. Public Sub CheckA()
  96. If Answer.Text = "" Then 'Make sure the text box isn't empty
  97. Exit Sub
  98. End If
  99. If Answer.Text = AnswerN Then 'See if the answer is correct
  100. 'Answer is correct, add to the right number and restart the questions
  101. NumRight = NumRight + 1
  102. Time.Enabled = False
  103. Time.Enabled = True
  104.   If CurTime > 1 Or CurTime < 1 Then
  105.   TimeLst.AddItem CurTime & " seconds"
  106.   Else
  107.   TimeLst.AddItem CurTime & " second"
  108.   End If
  109. CurTime = 0
  110. Answer.Text = ""
  111. GenQ
  112. Else 'Answer isn't correct, so add to the wrong number and give them a msgbox
  113. NumWrong = NumWrong + 1
  114. MsgBox "Wrong answer!", 48, "Wrong"
  115. End If
  116. End Sub
  117.  
  118. Public Sub StopT() 'This will stop the tutor and give people their "scores"
  119. Dim i As Integer
  120. Answer.Text = ""
  121. Problem.Text = ""
  122. PauseCmd.Caption = "Pause"
  123. StatsFrm.Show
  124. StatsFrm.NumRight.Caption = NumRight
  125. StatsFrm.NumWrong.Caption = NumWrong
  126. StatsFrm.Times.Clear
  127. For i = 0 To TimeLst.ListCount - 1
  128. StatsFrm.Times.AddItem TimeLst.List(i)
  129. Next i
  130. TutorFrm.Hide
  131. End Sub
  132.  
  133. Public Sub GenQ() 'Here is where the question is generated
  134. Dim RndNum As Integer
  135. Dim Num1 As Long
  136. Dim Num2 As Long
  137. Dim RNum1 As Long
  138. Dim RNum2 As Long
  139. Dim NumA As Long
  140. Randomize Timer
  141. 'Pick one of the math types selected before
  142. RndNum = Int(((OptionT.ListCount - 1) - 0 + 1) * Rnd)
  143. RndNum = OptionT.List(RndNum)
  144. 'Here is where we calculate what numbers should be used in the problem
  145. '--------------------------------------------------
  146.   If RndNum < 2 Then
  147.     If SetupFrm.OptionD(0).Value = True Then
  148.     Num1 = Int((10 - 1 + 1) * Rnd + 1)
  149.     Num2 = Int((10 - 1 + 1) * Rnd + 1)
  150.     ElseIf SetupFrm.OptionD(1).Value = True Then
  151.     Num1 = Int((100 - 1 + 1) * Rnd + 1)
  152.     Num2 = Int((100 - 1 + 1) * Rnd + 1)
  153.     Else
  154.     Num1 = Int((1000 - 1 + 1) * Rnd + 1)
  155.     Num2 = Int((1000 - 1 + 1) * Rnd + 1)
  156.     End If
  157.   ElseIf RndNum = 2 Then
  158.     If SetupFrm.OptionD(0).Value = True Then
  159.     Num1 = Int((12 - 1 + 1) * Rnd + 1)
  160.     Num2 = Int((12 - 1 + 1) * Rnd + 1)
  161.     ElseIf SetupFrm.OptionD(1).Value = True Then
  162.     Num1 = Int((25 - 1 + 1) * Rnd + 1)
  163.     Num2 = Int((25 - 1 + 1) * Rnd + 1)
  164.     Else
  165.     Num1 = Int((100 - 1 + 1) * Rnd + 1)
  166.     Num2 = Int((100 - 1 + 1) * Rnd + 1)
  167.     End If
  168.   ElseIf RndNum = 3 Then
  169.     If SetupFrm.OptionD(0).Value = True Then
  170.     Num1 = Int((5 - 1 + 1) * Rnd + 1)
  171.     Num2 = Num1 * Int((3 - 2 + 1) * Rnd + 2)
  172.     ElseIf SetupFrm.OptionD(1).Value = True Then
  173.     Num1 = Int((15 - 1 + 1) * Rnd + 1)
  174.     Num2 = Num1 * ((5 - 1 + 1) * Rnd + 1)
  175.     Else
  176.     Num1 = Int((100 - 1 + 1) * Rnd + 1)
  177.     Num2 = Num1 * ((10 - 1 + 1) * Rnd + 1)
  178.     End If
  179.   ElseIf RndNum = 4 Then
  180.     If SetupFrm.OptionD(0).Value = True Then
  181.     Num1 = Int((10 - 1 + 1) * Rnd + 1)
  182.     Num2 = Int((2 - 0 + 1) * Rnd + 1)
  183.     ElseIf SetupFrm.OptionD(1).Value = True Then
  184.     Num1 = Int((10 - 1 + 1) * Rnd + 1)
  185.     Num2 = Int((4 - 1 + 1) * Rnd + 1)
  186.     Else
  187.     Num1 = Int((10 - 1 + 1) * Rnd + 1)
  188.     Num2 = Int((10 - 0 + 1) * Rnd + 1)
  189.     End If
  190.   Else
  191.     If SetupFrm.OptionD(0).Value = True Then
  192.     Num1 = Int((2 - 0 + 1) * Rnd + 1)
  193.     Num2 = Int((10 - 1 + 1) * Rnd + 1) ^ Num1
  194.     ElseIf SetupFrm.OptionD(1).Value = True Then
  195.     Num1 = Int((4 - 1 + 1) * Rnd + 1)
  196.     Num2 = Int((10 - 1 + 1) * Rnd + 1) ^ Num1
  197.     Else
  198.     Num1 = Int((10 - 0 + 1) * Rnd + 1)
  199.     Num2 = Int((10 - 1 + 1) * Rnd + 1) ^ Num1
  200.     End If
  201.   End If
  202. '--------------------------------------------------
  203. 'Now we are generating the answers and showing out the problem
  204. '--------------------------------------------------
  205.     If RndNum = 0 Then
  206.     RNum1 = Num1
  207.     RNum2 = Num2
  208.     NumA = Val(RNum1) + Val(RNum2)
  209.     Problem.Text = RNum1 & "+" & RNum2 & "=?"
  210.     ElseIf RndNum = 1 Then
  211.       If Num1 > Num2 Then
  212.       RNum1 = Num1
  213.       RNum2 = Num2
  214.       ElseIf Num2 > Num1 Then
  215.       RNum1 = Num2
  216.       RNum2 = Num1
  217.       Else
  218.       RNum1 = Num1
  219.       RNum2 = Num2
  220.       End If
  221.     NumA = RNum1 - RNum2
  222.     Problem.Text = RNum1 & "-" & RNum2 & "=?"
  223.     ElseIf RndNum = 2 Then
  224.       If Int((2 - 1 + 1) * Rnd + 1) = 1 Then
  225.       RNum1 = Num1
  226.       RNum2 = Num2
  227.       Else
  228.       RNum1 = Num2
  229.       RNum2 = Num1
  230.       End If
  231.     NumA = RNum1 * RNum2
  232.     Problem.Text = RNum1 & "╫" & RNum2 & "=?"
  233.     ElseIf RndNum = 3 Then
  234.     RNum1 = Num2
  235.     RNum2 = Num1
  236.     NumA = RNum1 / RNum2
  237.     Problem.Text = RNum1 & "≈" & RNum2 & "=?"
  238.     ElseIf RndNum = 4 Then
  239.     RNum1 = Num1
  240.     RNum2 = Num2
  241.     NumA = RNum1 ^ RNum2
  242.     Problem.Text = RNum1 & "^" & RNum2 & "=?"
  243.     Else
  244.     RNum1 = Num2
  245.     RNum2 = Num1
  246.     NumA = RNum1 ^ (1 / RNum2)
  247.     Problem.Text = RNum1 & "^1/" & RNum2 & "=?"
  248.     End If
  249. '--------------------------------------------------
  250.     AnswerN = NumA 'Save the answer for further uses
  251. End Sub
  252.  
  253. Private Sub ExitCmd_Click() 'Unload all of the forms and exit the program
  254. Unload SetupFrm
  255. Unload StatsFrm
  256. Unload Me
  257. End
  258. End Sub
  259.  
  260. Private Sub Form_Load() 'Setup a couple things so the program will work right
  261. Startup
  262. End Sub
  263.  
  264. Private Sub Form_Unload(Cancel As Integer) 'Jump to the exit sub
  265. ExitCmd_Click
  266. End Sub
  267.  
  268. Private Sub PauseCmd_Click()
  269. If PauseCmd.Caption = "&Pause" Then 'If the program isn't paused then pause it
  270. Time.Enabled = False
  271. Answer.Locked = True 'Keep people from "exploiting" the timer pause
  272. PauseCmd.Caption = "Un&Pause"
  273. Else 'If the program is paused then unpause it
  274. Time.Enabled = True
  275. Answer.Locked = False
  276. PauseCmd.Caption = "&Pause"
  277. End If
  278. End Sub
  279.  
  280. Private